package com.security.common;

/**
 * 作者：lin
 * 功能：
 * 时间：2023/5/5 10:34
 */
public class Result<T> {
    public Integer code;
    public String msg;

    public T data;

    public Result() {
    }

    public Result(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }


    public static <T> Result<T> success() {
        return success(RespCode.SUCCESS.getCode(), RespCode.SUCCESS.getMsg(), null);
    }

    public static <T> Result<T> success(T data) {
        return success(RespCode.SUCCESS.getCode(), RespCode.SUCCESS.getMsg(), data);
    }

    public static <T> Result<T> success(Integer code, String msg, T data) {
        return new Result<>(code, msg, data);
    }

    public static <T> Result<T> fail() {
        return success(RespCode.FAIL.getCode(), RespCode.FAIL.getMsg(), null);
    }

    public static <T> Result<T> fail(T data) {
        return success(RespCode.FAIL.getCode(), RespCode.FAIL.getMsg(), data);
    }

    public static <T> Result<T> fail(Integer code, String msg, T data) {
        return new Result<>(code, msg, data);
    }

    public static <T> Result<T> fail(RespCode respCode, T data) {
        return fail(respCode.getCode(), respCode.getMsg(), data);
    }
}
